package com.sicau.smarttraceplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.smarttraceplatform.entity.Area;
import com.sicau.smarttraceplatform.entity.param.area.AreaQueryParam;
import com.sicau.smarttraceplatform.mapper.AreaMapper;
import com.sicau.smarttraceplatform.service.AreaService;
import com.sicau.smarttraceplatform.utils.QueryWrapperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 地区 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2020-05-24
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {

    @Resource
    private AreaMapper areaMapper;

    @Override
    public Area queryByEntity(Area area) {
        area.setCreated(null).setModified(null);
        QueryWrapper<Area> queryWrapper = QueryWrapperUtil.getQueryWrapper(Area.class, Area.class, area);
        queryWrapper.orderByDesc("id");
        List<Area> areaList = areaMapper.selectList(queryWrapper);
        if (areaList!=null&&areaList.size()!=0){
            return areaList.get(0);
        }
        return null;
    }

    @Override
    public List<Area> queryByCondition(AreaQueryParam areaQueryParam) {
        QueryWrapper<Area> queryWrapper = QueryWrapperUtil.getQueryWrapper(Area.class, AreaQueryParam.class, areaQueryParam);
        List<Area> areaList = areaMapper.selectList(queryWrapper);
        return areaList;
    }
}
